package com.example.dockerdemo.configuration;

import com.example.dockerdemo.interceotor.MyInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @PACKAGE_NAME: com.example.dockerdemo.configuration
 * @NAME: WebConfig
 * @description: MVC相关配置
 * @DATE: 2024/5/14
 * @USER: fz
 **/
@Configuration
public class WebConfig implements WebMvcConfigurer {

    // 静态资源映射
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/test/static/**")
                .addResourceLocations("classpath:/static/");

        // 本地图片
        registry.addResourceHandler("/test/images/**")
                .addResourceLocations("file:C:/Users/35818/Pictures/");
    }

    // 拦截器配置
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 黑名单
        ArrayList<String> blackList = new ArrayList<>();
        blackList.add("/test/black/**");
        // 白名单
        ArrayList<String> whiteList = new ArrayList<>();
        whiteList.add("/test/white/**");

        registry.addInterceptor(new MyInterceptor())
                .addPathPatterns(blackList)
                .excludePathPatterns(whiteList);
    }
}
